//
//  WLMainViewController.swift
//  WLWeibo
//
//  Created by Devil on 16/8/11.
//  Copyright © 2016年 Wiliam. All rights reserved.
//

import UIKit

class WLMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //实例化自定义tabBar
        let tabBar = WLTabBar()
        //设置代理
        tabBar.homeDelegate = self
        //通过KVC给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        
        
        addChildViewController(WLHomeViewController(), imgNmae: "tabbar_home", title: "首页")
        addChildViewController(WLMessageViewController(), imgNmae: "tabbar_message_center", title: "消息")
        addChildViewController(WLDiscoverViewController(), imgNmae: "tabbar_discover", title: "发现")
        addChildViewController(WLProfileViewController(), imgNmae: "tabbar_profile", title: "我")
        
        
        
        
        
    }
    
    func addChildViewController(Vc:UIViewController,imgNmae:String,title:String){
        
        Vc.title = title
        
        Vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        Vc.tabBarItem.image = UIImage(named: imgNmae)
        
        Vc.tabBarItem.selectedImage = UIImage(named: "\(imgNmae)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        addChildViewController(UINavigationController(rootViewController:Vc))
        
        
    }
}

extension WLMainViewController:WLTabBarDelegate{
    
    func tabBarButtonClick() {
        print("按钮被点击了")
        if !WLUserAccountViewModel.sharedTools.isLogin{
            print("请登录")
            return
        }
        let composeVc = WLComposeViewController()
        self.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
        
    }
    
}
